@extends('manage.layout')

@section('content')
    <div class="content">
        <!-- Content Header (Page header) -->
        <section class="content-header">
            <h1>
                管理员列表&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="/system/admin/add" class="btn btn-primary">添加管理员</a>
            </h1>
            <ol class="breadcrumb">
                <li><a href="#"><i class="fa fa-dashboard"></i> Home</a></li>
                <li><a href="#">admin</a></li>
            </ol>
            {{--<div class="input-group margin">--}}
                {{--<form action="{{ url('admin/manage') }}" method="post" >--}}
                    {{--{{ csrf_field() }}--}}
                    {{--<select style="width: 150px"  name="searchtype" class="form-control">--}}
                        {{--@foreach($manages['searchtype'] as $value)--}}
                            {{--<option value="{{ $value['id'] }}">{{ $value['searchtype'] }}</option>--}}
                        {{--@endforeach--}}
                    {{--</select>--}}
                    {{--<input style="width: 200px"  name="param" type="text" class="form-control">--}}
                    {{--<input  type="submit" class="btn btn-info btn-flat" value="Go!">--}}
                {{--</form>--}}
            {{--</div>--}}
        </section>

        <!-- Main content -->
        <section class="content">
            <div class="row">
                <div class="col-xs-12">
                    <div class="box">
                        <div class="box-header with-border">
                            <h3 class="box-title">内容</h3>
                        </div>
                        <div class="box-body">
                            <table class="table table-bordered table-hover"  style=" text-align: center;">
                               <tr>
                                    @foreach($navigation as $value)
                                        <th style="text-align:center">{{ $value['navigation'] }}</th>
                                    @endforeach
                                    <th style="text-align: center;">操作</th>
                                </tr>
                                @foreach($adminInfo as $admin)
                                    <tr>
                                        <td>{{ $admin['id'] }}</td>
                                        {{--<td>{{ $admin['create_time']}}</td>--}}
                                        <td>{{ $admin['update_time']}}</td>
                                        <td>{{ $admin['rank']}}</td>
                                        <td>{{ $admin['nickname']}}【{{ $admin['username']}}】</td>
                                        <td>{{ $admin['roleName']}}</td>
                                        <td>{{ $admin['ip'] or '暂无记录'}}</td>
                                        <td>{{ $admin['login_time'] or '暂无记录'}}</td>
                                        <td>{{ $admin['login_number']}}</td>
                                        <td>
                                            @if($admin['status'] == 0)
                                                <label>禁用</label>
                                            @elseif($admin['status'] == 1)
                                                <label>启用</label>
                                            @endif
                                        </td>
                                        <td  style="text-align:center;">
                                            <a class="btn btn-primary btn-xs"  href="{{ url('system/admin/update/'.$admin['id']) }}">修改<a>
                                            @if($admin['status'] == 0)
                                                <a class="btn btn-success btn-xs"  onclick="setStatus('{{$admin['id']}}',1)">启用<a>
                                            @elseif($admin['status'] == 1)
                                                <a class="btn btn-warning btn-xs"  onclick="setStatus('{{$admin['id']}}',0)">禁用<a>
                                            @endif
                                            {{--<a class="btn btn-danger btn-xs" onclick="deleteAdmin({{$admin['id']}})">删除<a>--}}
                                        </td>
                                    </tr>
                                @endforeach
                            </table>
                        </div>
                        <div calss="pages" style="text-align: center;">
                            @if(count($adminInfo) > 1)
                            {{ $adminInfo->links() }}
                            @endif
                        </div>

                        <!-- /.box -->
                    </div>

                    <!-- /.row -->

        </section>
        <!-- /.content -->
    </div>
    <!-- /.content-wrapper -->
@stop
@section('script')
    <script>
        function deleteAdmin(id) {
            layer.confirm('删除后不可恢复，是否继续?', {
                btn:['确定','取消']
            },function() {
                $.ajax({
                    url: '/system/admin/delAdmin',
                    type: "GET",
                    data: {id:id},
                    dataType: "json",
                    success: function(res) {
                        console.log(res);
                        if(res.error == 0) {
                            window.location.href = "/system/admin";
                            layer.msg(res.msg,{icon:1});
                        }
                        else {
                            layer.msg(res.msg,{icon:2});
                        }
                    },
                    error:function(){
                        layer.msg('ERROR');
                    }
                });
            });
        }
        //禁用,启用
        function setStatus(id,status) {
            $.ajax({
                url: '/system/admin/setStatus',
                type: "GET",
                data: {id:id,status:status},
                dataType: "json",
                success: function(res) {
                    console.log(res);
                    if(res.error == 0) {
                        window.location.href=window.location.href;
                        layer.msg(res.msg, {time:1500, icon:1})
                    }
                    else {
                        layer.msg(res.msg, {time:1500, icon:2})
                    }
                }
            });
        }
    </script>
@stop
